unit uPCBRules ;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  TBXDkPanels,
  SpTBXControls,
  StdCtrls,
  SpTBXEditors,
  VirtualTrees,
  SpTBXTabs,
  TB2ExtItems,
  SpTBXItem,
  TB2Item,
  TBX ;

type
  TfrmPCBRules = class( TFrame )
    tcProject : TSpTBXTabControl ;
    SpTBXTabItem3 : TSpTBXTabItem ;
    SpTBXTabItem1 : TSpTBXTabItem ;
    SpTBXRightAlignSpacerItem1 : TSpTBXRightAlignSpacerItem ;
    cbiUnits : TSpTBXComboBoxItem ;
    SpTBXTabSheet1 : TSpTBXTabSheet ;
    vstLayers : TVirtualStringTree ;
    SpTBXTabSheet3 : TSpTBXTabSheet ;
    SpTBXLabelItem1 : TSpTBXLabelItem ;
    SpTBXPanel1: TSpTBXPanel;
    SpTBXGroupBox4: TSpTBXGroupBox;
    ediPCBWidth: TSpTBXSpinEdit;
    ediPCBHeight: TSpTBXSpinEdit;
    SpTBXLabel4: TSpTBXLabel;
    SpTBXLabel10: TSpTBXLabel;
    SpTBXGroupBox10: TSpTBXGroupBox;
    ediTrackWidth: TSpTBXSpinEdit;
    ediTrackSpacing: TSpTBXSpinEdit;
    SpTBXLabel7: TSpTBXLabel;
    SpTBXLabel8: TSpTBXLabel;
    SpTBXGroupBox7: TSpTBXGroupBox;
    ediPartGrid: TSpTBXSpinEdit;
    ediViaGrid: TSpTBXSpinEdit;
    SpTBXLabel1: TSpTBXLabel;
    SpTBXLabel2: TSpTBXLabel;
    ediTrackGrid: TSpTBXSpinEdit;
    SpTBXLabel3: TSpTBXLabel;
    SpTBXGroupBox9: TSpTBXGroupBox;
    ediViaOutRing: TSpTBXSpinEdit;
    ediViaInRing: TSpTBXSpinEdit;
    SpTBXLabel5: TSpTBXLabel;
    SpTBXLabel6: TSpTBXLabel;
    ediViaDrill: TSpTBXSpinEdit;
    SpTBXLabel9: TSpTBXLabel;
    procedure cbiUnitsChange( Sender : TObject ; const Text : WideString ) ;
  private
    { Private declarations }
    function GetPCBHeight : single ;
    function GetPCBWidth : single ;
    function GetUnits : single ;
  public
    { Public declarations }
    property PCBWidth : single read GetPCBWidth ;
    property PCBHeight : single read GetPCBHeight ;

    property Units : single read GetUnits ;
  end ;

implementation

{$R *.dfm}

function TfrmPCBRules.GetPCBHeight : single ;
begin
  Result := ediPCBWidth.Value * Units ;
end ;

function TfrmPCBRules.GetPCBWidth : single ;
begin
  Result := ediPCBHeight.Value * Units ;
end ;

function TfrmPCBRules.GetUnits : single ;
begin
  if cbiUnits.Text = 'mm' then
    Result := 1000 / 25.4               // mm
  else if cbiUnits.Text = '"' then
    Result := 1000                      // inch
  else
    Result := 1 ;                       // mil
end ;

procedure TfrmPCBRules.cbiUnitsChange( Sender : TObject ; const Text : WideString ) ;
var
  iText             : string ;
  u                 : single ;
begin
  u := GetUnits ;
  ediPCBWidth.Value := ediPCBWidth.Value * u ;
  ediPCBHeight.Value := ediPCBHeight.Value * u ;
  ediViaInRing.Value := ediViaInRing.Value * u ;
  ediViaOutRing.Value := ediViaOutRing.Value * u ;
  ediViaDrill.Value := ediViaDrill.Value * u ;
  ediTrackWidth.Value := ediTrackWidth.Value * u ;
  ediTrackSpacing.Value := ediTrackSpacing.Value * u ;
  ediPartGrid.Value := ediPartGrid.Value * u ;
  ediViaGrid.Value := ediViaGrid.Value * u ;
  ediTrackGrid.Value := ediTrackGrid.Value * u ;

  if Text = 'mm' then
    iText := 'mm'
  else if Text = 'inch' then
    iText := '"'
  else if Text = 'mil' then
    iText := 'mil' ;

  ediPCBWidth.PostFix := iText ;
  ediPCBHeight.PostFix := iText ;
  ediViaInRing.PostFix := iText ;
  ediViaOutRing.PostFix := iText ;
  ediViaDrill.PostFix := iText ;
  ediTrackWidth.PostFix := iText ;
  ediTrackSpacing.PostFix := iText ;
  ediPartGrid.PostFix := iText ;
  ediViaGrid.PostFix := iText ;
  ediTrackGrid.PostFix := iText ;
end ;

end.

